Skip to content

fix(ida): thin the selected FAT slice into the private headless input - #2201

Merged
morluto merged 1 commit into
morluto:mainfrom
akushonkamen:fix/2139-ida-thin-fat-slice
Oct 12, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
akushonkamen:fix/2139-ida-thin-fat-slice

Conversation

@akushonkamen

Copy link
Copy Markdown
Contributor

Summary

Universal Mach-O admission resolved and reported the host-preferred slice's architecture, but the IDA provider's private input copy handed the whole FAT container to upstream idalib, which then picked its own slice (x86_64 for /bin/cat) while Evidence labeled the session arm64. FAT parsing now exports the selected slice's byte range as universalSlice, and the private input copy writes exactly those bytes.

Fixes #2139

Problem and expected behavior

On an arm64 macOS host with the IDA provider (headless idalib-mcp), opening a universal binary reports architecture: "arm64" in open_binary, every Evidence subject, and the analysis profile, while the analysed code is the x86_64 slice (push rbp; mov rbp, rsp SysV prologue on start). The violated invariant: the architecture recorded in Evidence must describe the bytes the provider actually analyses.

Root cause, read from src at the base of this branch:

  • parseFatMachO (src/domain/binaryTarget.ts:103; :113-:159 at base 5190843f8) already resolved the host-compatible preferred slice and computed its byte range, but the resolved target kept the whole FAT path with no slice offset/size exported.
  • BinaryTargetResolver.ts:70 uses process.arch only for the reported architecture; the resolved path stays the whole container.
  • IdaWorkspace.copyInput (src/ida/IdaWorkspace.ts:64) copied the whole FAT into the private workspace, so upstream idalib chose its own slice.

Change and scope

  • The FAT parse result and BinaryTarget's mach-o-universal variant now carry a required universalSlice { offset, size } (src/domain/binaryTargetTypes.ts:34, src/domain/binaryTarget.ts:174). Container-identity semantics are unchanged: mach-o-universal remains the container format across Evidence, snapshots, and provider routing, and sha256 stays the whole-file digest.
  • copyInput became a single-pass bounded streaming copy (64 KB chunks): the whole-file sha256 still anchors the copy against admission-time source changes, but only the selected slice's bytes are written, and the digest of the thinned product is exposed as inputSha256 (src/ida/IdaWorkspace.ts:38).
  • The post-operation identity check in IdaSessionClient.ts:510 accordingly anchors the thinned product instead of the whole container.
  • Thin targets keep the whole-file copy. Intentionally not included: live IDA validation (no license available here — disclosed below), and any change to the snapshot cache key.

Contract and boundary impact

  • Semantic owner and earliest changed stage: domain binary-target parsing owns the slice byte range; earliest changed stage is target resolution.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: the IDA provider's private input for mach-o-universal targets is now the selected slice, so upstream idalib can no longer pick a different slice than the reported architecture. Other providers and thin formats are untouched.
  • Evidence, artifact, provenance, or reconstruction contract: Evidence subject architecture now describes the analysed bytes. The snapshot cache key remains the whole-FAT sha256, so snapshots produced before this fix can theoretically still replay against the whole container — disclosed as a known gap.
  • Process execution, authorization, cleanup, or containment impact: none; the copy stays inside the existing private workspace with the same bounded-write guarantees.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • Tests added: src/ida/IdaWorkspaceThinning.test.ts (5 tests: arm64 slice thinning, x86_64 slice when the host is intel, whole-file copy for thin targets, rejection of a universal source changed after admission, headless session bound to the thinned input identity). analysisSnapshot and binaryTargetTypes fixtures updated for the required universalSlice.

  • Base reproduction (executed): on clean origin/main 58fb37207 (this branch's rebased parent) the new suite fails 3 failed | 2 passed (5) — the two thinning tests and the whole-file-copy test fail (src/ida/IdaWorkspaceThinning.test.ts:48, :74, :91: the copied input is the whole FAT, not the 32-byte slice, and inputSha256 is undefined) — and passes with this change.

  • Remaining proof gaps: no live IDA analysis (unlicensed here); universal-slice behavior verified with synthetic lipo fixtures, not real-IDA sessions.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npx vitest run --project adapters src/ida/IdaWorkspaceThinning.test.ts — 5 passed (5) with the change; 3 failed | 2 passed on clean origin/main 58fb37207 (base reproduction above)
  • npx vitest run --project adapters src/ida/ — 12 files, 116 passed
  • npx vitest run --project domain --project services — 201 files, 2854 passed, 3 skipped (full projects after rebasing onto 58fb37207)
  • npx vitest run --project adapters src/ghidra/GhidraProvider.behavior.test.ts src/hopper/HopperAnalysisProfile.test.ts — 2 files, 50 passed
  • npx vitest run --project boundary tests/boundary/filesystem/binaryTarget.test.ts tests/boundary/providers/native/artifactProvider.universalExtraction.test.ts — 2 files, 49 passed
  • npx vitest run --project mcp-boundary tests/boundary/mcp/nativeSignatureTargetBindingMcp.test.ts — 1 file, 2 passed
  • npx oxfmt . (no-op; tree unchanged) then npx vitest run src/ida/ src/domain/binaryTarget.test.ts — 13 files, 151 passed
  • npx vitest run src/ida/IdaWorkspaceThinning.test.ts src/ida/IdaWorkspaceOwnership.test.ts src/ida/IdaSessionClient.test.ts — 3 files, 45 passed
  • npx tsc --noEmit — clean
  • npx oxlint — 866 warnings and 0 errors, identical multiset to a clean origin/main 58fb37207 worktree (verified by diffing normalized warning triples; the only differences are two pre-existing warnings whose line numbers shifted inside edited files — zero new)
  • npx oxfmt --check on the 9 changed files — all pass
  • npx knip — 1 unresolved import (#javascript-analysis-worker), identical on clean origin/main (pre-existing)
  • Scratch end-to-end fixture (executed during validation of this branch, removed afterwards): clang -arch arm64 / -arch x86_64 + lipo -create built a real 33224-byte universal (x86_64@4096+4272, arm64@16384+16840); the copyInput product was byte-identical to the clang -arch arm64 original, LE magic 0xfeedfacf, cputype 0x0100000c, length = universalSlice.size = 16840
  • Not run: live IDA analysis — no license/authorization available in this environment (disclosed above)

Compatibility, safety, and release

  • Breaking changes or migration steps: none; no public CLI/MCP contract changes.
  • Real Hopper/Ghidra, browser, or OS coverage: Ghidra/Hopper behavior suites pass (2 files / 50 tests); macOS FAT behavior covered by synthetic universal fixtures, not a licensed IDA install.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the bounded streaming copy keeps the digest anchor against source swaps between admission and copy; no new subprocesses, network, or elevated access.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output. (No output format change; the fix corrects which bytes are analysed.)
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

Universal Mach-O admission reported the selected slice architecture while the IDA provider's private input copy handed the whole FAT container to upstream idalib, which then picked its own slice (x86_64 for /bin/cat) while Evidence labeled the session arm64. FAT parsing now exports the selected slice's byte range as universalSlice, and the private input copy writes exactly those bytes: the whole source digest still anchors the copy against admission-time changes, and the thinned result anchors the post-operation identity check.

Thin targets keep the whole-file copy, and mach-o-universal remains the container format across Evidence, snapshots, and provider routing.

Validation: typecheck, oxlint (no new warnings), oxfmt, and targeted vitest runs — ida adapters 12 files/116 tests, domain and services projects 60 files/736 tests, ghidra/hopper behavior 2 files/50 tests, filesystem and universal-extraction boundary 2 files/49 tests, native signature MCP 1 file/2 tests, plus a new thinning suite (5 tests, red before the fix: 3 failed). The thinned product was verified byte-identical to the `clang -arch arm64` input of a `lipo -create` universal fixture. Controlled fixtures only; no live IDA analysis was performed for this change.

Closes morluto#2139
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-12T13:34:01.359866Z 8584547 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@morluto
morluto merged commit 10400fd into morluto:main Oct 12, 2026
30 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@akushonkamen
akushonkamen deleted the fix/2139-ida-thin-fat-slice branch October 25, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] IDA provider analyzes the x86_64 slice of a universal Mach-O while reporting arm64

2 participants